

// First we create the namespace.
BasicMVC.addNamespace("examplenamespace.foo.faa");


// Now we create two events.
// The event has to have a type attribute. Its how it know what it is.
examplenamespace.foo.faa.LoginRequestEvent = function(userEmail, userPassword)
{
	this.type = "genericServer.events.requests.LoginRequestEvent";
	this.userEmail = userEmail;
	this.userPassword = userPassword;
}

examplenamespace.foo.faa.LoginResponseEvent = function(name)
{
	this.type = "genericServer.events.requests.LoginResponseEvent";
	this.name = name;
}

// An example model.
// Always extend the base class.
examplenamespace.foo.faa.Model = BasicMVC.Base.extend({

	// the constructor
	constructor: function()
	{
		this.name = "examplenamespace.foo.faa.Model";
	},

	// the list of event listeners (it is checked when the class is registreted to the master
	eventListeners: function()
	{
		return [
			{event: examplenamespace.foo.faa.LoginRequestEvent, handler: this.login}
		];
	},

	login: function(event)
	{

		console.log("examplenamespace.foo.faa.LoginRequestEvent executed");
		var loginResponseEvent = new examplenamespace.foo.faa.LoginResponseEvent("John Doe");
		this.sendEvent(loginResponseEvent);
	}

});

examplenamespace.foo.faa.Control = BasicMVC.Base.extend({

	constructor: function()
	{
		this.name = "examplenamespace.foo.faa.Control";

		$("#loginButton").bind("click",
			this.localScope(
				this.doLogin
			)
		);
	},

	eventListeners: function()
	{
		return [

		];
	},

	eventHandlers: function(event)
	{
		
	},

	doLogin: function()
	{
		var loginRequestEvent = new examplenamespace.foo.faa.LoginRequestEvent("john@doe.com", "hello");
		this.sendEvent(loginRequestEvent);
	}



});

examplenamespace.foo.faa.View = BasicMVC.Base.extend({

	constructor: function()
	{
		this.name = "examplenamespace.foo.faa.View";
	},

	eventListeners: function()
	{
		return [
			{event: examplenamespace.foo.faa.LoginResponseEvent, handler: this.userHasLoggedIn}
		];
	},

	userHasLoggedIn: function(event)
	{
		$("#message").html("Logged in as '" + event.name + "'!");
		console.log("examplenamespace.foo.faa.LoginResponseEvent executed");
	}

});